package cn.superchart.web.core.config;
import cn.hutool.core.io.resource.ClassPathResource;
import freemarker.cache.FileTemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.DefaultObjectWrapper;
import freemarker.template.TemplateException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;

import java.io.IOException;

/**
 * @author LONG
 */
@Slf4j
@org.springframework.context.annotation.Configuration
public class FreeMarkConfig {

    @Bean
    public Configuration configuration() throws TemplateException, IOException {
        Configuration cfg = new Configuration(Configuration.VERSION_2_3_33);
        ClassPathResource classPathResource = new ClassPathResource("templates");
        cfg.setTemplateLoader(new FileTemplateLoader(classPathResource.getFile()));
        cfg.setObjectWrapper(new DefaultObjectWrapper(Configuration.VERSION_2_3_33));
        cfg.setWrapUncheckedExceptions(true);
        cfg.setClassicCompatible(true);
        cfg.setDefaultEncoding("UTF-8");
        cfg.setSetting("number_format","0.##");
        return cfg;
    }
}
